﻿//-------------------------------------------------------------------
//	Copyright (c) 2010-2014  Zhirnov Andrey
//	This file is part of the "UX Standard Lib" project.
//	See copyright notice in "UX_STL_Core.h".
//-------------------------------------------------------------------
/*
	Description:	2x2, 2x3, 2x4 matrices
*/

#ifndef _UXS_MATRIX2_H
#define _UXS_MATRIX2_H

#pragma once

#include "TMatrix.h"

namespace UX_STL
{
namespace UXMath
{
	

	//
	// Matrix 2x2
	//
	
#define C	2
#define R	2
#define MATRIX_METHODS() \
		TMatrix(T _00, T _10, \
				T _01, T _11); \
		TMatrix(const col_t &c0, \
				const col_t &c1); \
		\
		Self		Inverse() const; \


#include "TMatrixCR.h"



	template <typename T>
	inline TMatrix<T,C,R>::TMatrix(T _00, T _10,
								   T _01, T _11)
	{
		_v[0][0] = _00;		_v[1][0] = _10;
		_v[0][1] = _01;		_v[1][1] = _11;
	}


	template <typename T>
	inline TMatrix<T,C,R>::TMatrix(const TVec<T,2> &c0, const TVec<T,2> &c1)
	{
		MemCopy( _v[0], c0.ptr(), sizeof(T)*R );
		MemCopy( _v[1], c1.ptr(), sizeof(T)*R );
	}
	

	template <typename T>
	inline TMatrix<T,C,R>  TMatrix<T,C,R>::Inverse() const
	{
		const T	det = _v[0][0] * _v[1][1] - _v[1][0] * _v[0][1];

		return Self(	  _v[1][1] / det,	- _v[1][0] / det,
						- _v[0][1] / det,	  _v[0][0] / det );
	}

#undef	R
#undef	C
#undef	MATRIX_METHODS


	
	

	//
	// Matrix 2x3
	//
	
#define C	2
#define R	3
#define MATRIX_METHODS() \
		TMatrix(T _00, T _10, \
				T _01, T _11, \
				T _02, T _12); \
		TMatrix(const col_t &c0, \
				const col_t &c1); \


#include "TMatrixCR.h"



	template <typename T>
	inline TMatrix<T,C,R>::TMatrix(T _00, T _10,
								   T _01, T _11,
								   T _02, T _12)
	{
		_v[0][0] = _00;		_v[1][0] = _10;
		_v[0][1] = _01;		_v[1][1] = _11;
		_v[0][2] = _02;		_v[1][2] = _12;
	}


	template <typename T>
	inline TMatrix<T,C,R>::TMatrix(const TVec<T,3> &c0, const TVec<T,3> &c1)
	{
		MemCopy( _v[0], c0.ptr(), sizeof(T)*R );
		MemCopy( _v[1], c1.ptr(), sizeof(T)*R );
	}

#undef	R
#undef	C
#undef	MATRIX_METHODS


	

	//
	// Matrix 2x4
	//
	
#define C	2
#define R	4
#define MATRIX_METHODS() \
		TMatrix(T _00, T _10, \
				T _01, T _11, \
				T _02, T _12, \
				T _03, T _13); \
		TMatrix(const col_t &c0, const col_t &c1); \


#include "TMatrixCR.h"



	template <typename T>
	inline TMatrix<T,C,R>::TMatrix(T _00, T _10,
								   T _01, T _11,
								   T _02, T _12,
								   T _03, T _13)
	{
		_v[0][0] = _00;		_v[1][0] = _10;
		_v[0][1] = _01;		_v[1][1] = _11;
		_v[0][2] = _02;		_v[1][2] = _12;
		_v[0][3] = _03;		_v[1][3] = _13;
	}


	template <typename T>
	inline TMatrix<T,C,R>::TMatrix(const TVec<T,4> &c0, const TVec<T,4> &c1)
	{
		MemCopy( _v[0], c0.ptr(), sizeof(T)*R );
		MemCopy( _v[1], c1.ptr(), sizeof(T)*R );
	}

#undef	R
#undef	C
#undef	MATRIX_METHODS


//-------------------------------------------------------------------

}	// UXMath
}	// UX_STL

#endif	// _UXS_MATRIX2_H